import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== Declare
const { $fn, $http, $Lazy } = window
// ===================================================================== Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
const message 			= $Lazy.file(()=>import('@antd/message'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data: [],
		pag: {},
		selectedKeys: [],
		forms : [
			{ label: '医院名称',		name: 'hosp_id', type: 'select',nameStr:'name' },
			{ label: '医院性质',		name: 'nature',			type: 'select', loading:true,	idStr:'code' },
			{ label: '医院代码',		name: 'hosp_code' },
			{ label: '医院条码',		name: 'hosp_spec' },
			{ label: '医院级别',		name: 'level',			type: 'select', loading:true,	idStr:'code' },
			{ label: '区域',		name: 'region_id',		type: 'select', loading:true },
			{ label: '业务员',		name: 'salesman_id',	type: 'select', loading:true },
		]
	}
	query = {enabled: '1'}
	model = {}
	act_id = ''
	
	open = (uuid) => {
		this.getSelect()
		this.modal.open()
		this.act_id = uuid
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 医院名称
			$fn.setRow(forms, 'hosp_id', await f.getCache({ api:'hospital' } ) )
			// 区域
			$fn.setRow(forms, 'region_id', await f.getCache({ api:'bs_area' } ) )
			//医院性质
			$fn.setRow(forms, 'nature', await f.getDicCache({ code:44100 } ) )
			//医院级别
			$fn.setRow(forms, 'level', await f.getDicCache({ code:39000 } ) )
			// 业务员
			$fn.setRow(forms, 'salesman_id', await f.getCache({ api:'salesman' } ) )
			//
			this.setState({ forms })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this, 'bs-hospital/index',)
	
	// 表单
	cols = [
		{ title: '医院代码',		dataIndex: 'hosp_code', 	...$fn.table.hosp_code },
		{ title: '医院条码', 	dataIndex: 'hosp_spec', 	...$fn.table.num },
		{ title: '医院名称', 	dataIndex: 'hosp_name', 	width:200 },
		{ title: '医院性质', 	dataIndex: 'nature_name', 	width:100 },
		{ title: '医院级别',		dataIndex: 'level_name', 	width:100 },
		{ title: '创建时间', 	dataIndex: 'create_at', 	...$fn.table.time },
	]
	
	render(){
		return TableModal.call(this,{ title: '参与医院', labelWidth:'s7', width:'90%', height:'80%',onOk:(selectedKeys)=>{
			$http.submit(null, 'act-conf-marketing/bindhosp', { param:{act_id: this.act_id, hosp_ids: selectedKeys } }).then(data=>{
				message.then(f=>f.success('添加成功'))
				this.modal.close()
				this.props.onRefresh()
			})
		}})

	}
}

export default Index